﻿using System;
using System.Collections.Generic;
using System.Text;
using DataBaseConnect.IRepositories;
using Entity;
using Utils;

namespace DataBaseConnect.App
{
    public class FlowAppService : IFlowAppService
    {
        private readonly IFlowRepository _flowRepository;

        public FlowAppService(IFlowRepository flowRepository)
        {
            _flowRepository = flowRepository;
        }

        /// <summary>
        /// 获取所有的流程和根据流程名称查询
        /// </summary>
        /// <param name="Name">流程名称</param>
        /// <returns></returns>
        public List<Flow> GetFlowList(string Name)
        {
            if (!string.IsNullOrEmpty(Name))
            {
                return _flowRepository.GetAllList(f => f.Name == Name);
            }
            else
            {
                return _flowRepository.GetAllList();
            }
        }

        /// <summary>
        /// 根据主键获取流程
        /// </summary>
        /// <param name="Id">id</param>
        /// <returns></returns>
        public List<Flow> GetFlowId(int Id)
        {
            return _flowRepository.GetAllList(f => f.Id == Id);
        }

        /// <summary>
        /// 添加流程信息
        /// </summary>
        /// <param name="Input">参数实体</param>
        /// <returns></returns>
        public ReceiveStatus AddFlowMsg(Flow Input)
        {
            ReceiveStatus receiveStatus = new ReceiveStatus();
            try
            {
                _flowRepository.Insert(Input, true);
                receiveStatus.msg = "新增成功";
            }
            catch (Exception ex)
            {
                receiveStatus.code = statuCode.Error;
                receiveStatus.msg = ex.Message;
            }
            return receiveStatus;
        }

        /// <summary>
        /// 获取所有流程分类
        /// </summary>
        /// <returns></returns>
        public List<FlowType> GetFlowTypesAll()
        {
            return _flowRepository.GetFlowTypesAll();
        }
    }
}
